﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using GuestBook_Lib;

namespace Guestbook_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Book book = new Book();
        private void button1_Click(object sender, EventArgs e)
        {
            bool temp = false;
            string mess = "";
            try
            {
                if (textBox1.Text == "")
                {
                    ApplicationException app = new ApplicationException("Error: You have to have a name!");
                    throw app;
                }
                if (numericUpDown1.Value != 0)
                {
                    if (textBox2.Text != "")
                    {
                        mess = book.AddSign(textBox1.Text, Convert.ToInt32(numericUpDown1.Value), textBox2.Text);
                    }
                    else
                    {
                        mess = book.AddSign(textBox1.Text, Convert.ToInt32(numericUpDown1.Value));
                    }
                }
                else
                {
                     mess = book.AddSign(textBox1.Text);
                }
                temp = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (temp == true)
                {
                    //MessageBox.Show("Thanks for Signing!");
                    listBox1.Items.Add(mess);
                    textBox1.Text = "";
                    textBox2.Text = "";
                    numericUpDown1.Value = 0;
                }
            }
            //Signiture sign = new Signiture("Cat");
            //Book book = new Book();
        }
        Settings s = new Settings();
        private void Form1_Load(object sender, EventArgs e)
        {
            //panel1.Visible = false;
            //string cap = "Error: Search File not found!";
            if (System.IO.File.Exists(@"C://Guestbook//Parts.txt") == true)
            {
                //cap = "Do not heisitate to ask for assistance in finding parts.";
            }
            if (s.ShowScouting() == false)
            {
                panel2.Visible = false;
            }
            else
            {
                panel2.Visible = true;
            }
            panel3.Visible = s.Survey();
            panel1.Visible = s.Show_Part();
            //toolTip1.SetToolTip(button5 , cap);
            //SpeechRecognizer rec = new SpeechRecognizer();
            UpdateVoid();
            //rec.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(name);
        }
        private void name(object sender, SpeechRecognizedEventArgs e)
        {

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
        private void UpdateVoid()
        {
            try
            {
                System.IO.Directory.CreateDirectory(@"C://Guestbook//Survey");
                string[] Array = System.IO.Directory.GetFiles(@"C://Guestbook//Survey");
                if (System.IO.File.Exists(@"C://Guestbook//Survey//Default.txt") == false)
                {
                    ApplicationException app = new ApplicationException("Error 0: Default survey file not found!");
                    //app.Message = "Default file not found!";
                    throw app;
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                statLabel.Text = "Status: Error; Ready to boot.";
                statLabel.ForeColor = System.Drawing.Color.Red;
            }
            finally
            {
                if (statLabel.ForeColor.Equals(System.Drawing.Color.Red) == false)
                {
                    statLabel.Text = "Status: File located!";
                    statLabel.ForeColor = System.Drawing.Color.Green;
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            UpdateVoid();
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void toolTip1_Popup(object sender, PopupEventArgs e)
        {
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
        Survey sv;
        private void constructSurveyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sv = new Survey(listBox2);
            sv.Call_Maker();
        }

        private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Options op = new Options();
            op.Show();
        }

        private void Form1_VisibleChanged(object sender, EventArgs e)
        {
            Form1_Load(sender, e); //Refresh the forms rules!
        }

        private void refreshPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1_Load(sender, e);
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            book.Save_to_String_File();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            book.Load_String_Book(listBox1);

        }

        private void loadSurveyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                sv.Null_Test();
            }
            catch (Exception ex)
            {
                sv = new Survey (listBox2);
            }
            OpenFileDialog o = new OpenFileDialog();
            o.Filter = "Survey Files (*.surv)|*.surv";
            o.ShowDialog();
            o.DefaultExt = ".surv";
            if (o.FileName != "" && o.FileName != "o")
            {
                sv.Load_File(o.FileName);
            }
        }

        private void buildNewToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
